Use case: IRDA transmit in DMA mode

This use case shows how to transmit IRDA data in DMA mode. In HAL2, IRDA support is handled via the HAL UART driver.

Sequence diagram

    @startuml
    participant "User Application" as p1
    participant "HAL IRDA driver" as p2
    participant "IRDAX_IRQHandler" as p5
    participant "DMA" as p3
    participant "DMAx_IRQHandler" as p4

    == initialization and configuration ==
    == IRDA HAL Transmit DMA ==
    p1->p2: <color: green> HAL_IRDA_Transmit_DMA(&hirda, aTxBuffer, DATA_TO_SEND_SIZE)
    note over p2 #00FF00
    Transmitting data ongoing
    end note
    p2->p3: HAL_DMA_Start_IT()
    p3-->p2: HAL_OK
    p2-->p1: HAL_OK

    p4<-: DMAx complete interrupt
    p4->p3: HAL_DMA_IRQHandler
    note over p3 #00FF00
    End of transmitting data
    end note
    p3->p2: XferCpltCallback
    p2->p2: Enable IRDAx Transmit Complete IRQ (TCIE)
    p5<-: IRDAx Transmit Complete (TCIE)
    p5->p2: HAL_IRDA_IRQHandler
    p2->p1: HAL_IRDA_TxCpltCallback(hirda->TxXferCount)
    @enduml

Code snippet

HAL1

HAL2

#define DATA_TO_SEND_SIZE           255

IRDA_HandleTypeDef hirda;
uint8_t aTxBuffer[DATA_TO_SEND_SIZE] = " **** IRDA Communication **** ";

/* Optional: register transmit-complete callback */
HAL_IRDA_RegisterCallback(&hirda, HAL_IRDA_TX_CB_ID, IRDA_TxCpltCallback);

/* Start transmit in DMA mode */
(void)HAL_IRDA_Transmit_DMA(&hirda, aTxBuffer, DATA_TO_SEND_SIZE);
#define DATA_TO_SEND_SIZE           255

hal_uart_handle_t huart;
uint8_t aTxBuffer[DATA_TO_SEND_SIZE] = " **** IRDA Communication **** ";

/* Optional: register transmit-complete callback */
HAL_UART_RegisterTxCpltCallback(&huart, UART_TxCpltCallback);

/* Start transmit in DMA mode */
(void)HAL_UART_Transmit_DMA(&huart, aTxBuffer, DATA_TO_SEND_SIZE);

Key changes

  1. HAL2 migrates from HAL_IRDA_Transmit_DMA() to HAL_UART_Transmit_DMA().

  2. DMA completion still triggers a TX complete interrupt path, but HAL2 uses HAL_UART_IRQHandler().

  3. Completion callback naming/parameters differ in HAL2 (byte count instead of element count).